package fireman;

import jade.core.*;
import jade.domain.FIPAAgentManagement.*;
import jade.lang.acl.*;
import jade.proto.AchieveREInitiator;

public class SendFinishDownload {

	AID sender;

	/**
	 * Send by the Civilians to Evacuators to inform they exit the building
	 */
	public void addBehaviour(Agent agent) {
		ACLMessage msg = new ACLMessage(ACLMessage.INFORM);
		msg.setProtocol(agents.UtilsAgents.PROTOCOL_DOWNLOAD);
		msg.setContent(agents.UtilsAgents.OUT);
		msg.setSender(agent.getAID());
		ServiceDescription sd = new ServiceDescription();
		sd.setType(agents.UtilsAgents.FIREMANAGER_AGENT);
		// this.sender=sender;
		msg.addReceiver(agents.UtilsAgents.searchAgent(agent, sd));
		msg.addReceiver(sender);
		agent.addBehaviour(new SendFinishWork(agent, msg));
	}

	public class SendFinishWork extends AchieveREInitiator {
		/**
         *
         */
		private static final long serialVersionUID = 1L;

		public SendFinishWork(Agent arg0, ACLMessage arg1) {
			super(arg0, arg1);
		}

		/**
		 * Receive inform from the manager harvester, and the content is
		 * "Be_scout".
		 */
		@Override
		protected void handleInform(ACLMessage msg) {
			//
			if ((msg.getProtocol().equals(agents.UtilsAgents.PROTOCOL_DOWNLOAD))
					&& (msg.getContent().equals(agents.UtilsAgents.OK))) {
				System.out.println("Evacuator informed that im safe."
						+ msg.getSender());
			} else
				System.out
						.println("Error in protocol in send download, repeat it.");
			// Cal tornar a cridar el protocol load.
		}
	}
}
